package Aula19;

import junit.framework.TestCase;

public class RotacoesTest extends TestCase {
	
	public Rotacoes r;
	
	protected void setUp() throws Exception {
		r = new Rotacoes();
	}

	public void testZigRight() {
		No raiz = new No(2);
		No no = new No(1);
		No no2 = new No(0);
		raiz.left = no;
		no.parent = raiz;
		no.left = no2;
		no2.parent = no;
		r.zigRight(no);
		assertTrue(no.parent == null);
		assertTrue(raiz.parent == no);
		assertTrue(no2.parent == no);
		assertTrue(no2.right == null);
		assertTrue(no2.left == null);
		assertTrue(raiz.right == null);
		assertTrue(raiz.left == null);
		assertTrue(no.right.key == raiz.key);
		assertTrue(no.left.key == no2.key);
	}

	public void testZigLeft() {
		No raiz = new No(2);
		No no = new No(4);
		No no2 = new No(3);
		raiz.right = no;
		no.parent = raiz;
		no.left = no2;
		no2.parent = no;
		r.zigLeft(no);
		assertTrue(no.parent == null);
		assertTrue(raiz.parent == no);
		assertTrue(no2.parent == raiz);
		assertTrue(no2.left == null);
		assertTrue(no2.right == null);
		assertTrue(raiz.right == no2);
		assertTrue(raiz.left == null);
		assertTrue(no.right == null);
		assertTrue(no.left.key == raiz.key);
		assertTrue(no.left.right.key == no2.key);
	}

	public void testZigZigRight() {
		No raiz = new No(5);
		No no = new No(4);
		No no2 = new No(1);
		No no3 = new No(2);
		raiz.left = no;
		no.parent = raiz;
		no.left = no2;
		no2.parent = no;
		no2.right = no3;
		no3.parent = no2;
		r.zigZigRight(no2);
		assertTrue(no2.parent == null);
		assertTrue(no2.right == no);
		assertTrue(no2.left == null);
		assertTrue(no.parent == no2);
		assertTrue(no.left == no3);
		assertTrue(no.right == raiz);
		assertTrue(no3.parent == no);
		assertTrue(no3.left == null);
		assertTrue(no3.right == null);		
		assertTrue(raiz.parent == no);
		assertTrue(raiz.left == null);
		assertTrue(raiz.right == null);
	}

	public void testZigZigLeft() {
	}

	public void testZigZagLeft() {
		No raiz = new No(4);
		No no = new No(1);
		No no2 = new No(3);
		No no3 = new No(2);
		raiz.left = no;
		no.parent = raiz;
		no.right = no3;
		no3.parent = no;
		no3.right = no2;
		no2.parent = no3;
		r.zigZagLeft(no3);
		assertTrue(no3.parent == null);
		assertTrue(no3.right == raiz);
		assertTrue(no3.left == no);
		assertTrue(no.parent == no3);
		assertTrue(no.left == null);
		assertTrue(no.right == null);
		assertTrue(no2.parent == raiz);
		assertTrue(no2.left == null);
		assertTrue(no2.right == null);		
		assertTrue(raiz.parent == no3);
		assertTrue(raiz.left == no2);
		assertTrue(raiz.right == null);
	}
	
	public void testZigZagRight() {
	}

}
